﻿using Best.SmartCms.Domain;
using Best.SmartCms.Dto.Response;
using Best.SmartCms.Dto;
using Best.SmartCms.Service;
using Microsoft.AspNetCore.Mvc;

namespace Best.SmartCms.API.Controllers
{
    /// <summary>
    /// Product
    /// </summary>
    public class ProductController : Controller
    {
        private readonly ProductService _productService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="productService"></param>
        public ProductController(ProductService productService)
        {
            _productService = productService;
        }


        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("product/pagelist")]
        public PagedResponse<ProductListDto> PageList([FromBody]ProductListQueryDto query)
        {
            var ret = _productService.PageList(query);
            return ret;
        }


        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("product/create")]
        public ApiResponse Create([FromBody]ProductEditDto dto)
        {
             _productService.Create(dto);
            return ApiResponse.Succeeds();
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("product/edit")]
        public ApiResponse Edit([FromBody]ProductEditDto dto)
        {
            _productService.Edit(dto);
            return ApiResponse.Succeeds();
        }


        /// <summary>
        /// 详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("product/Info")]
        public ApiResponse<ProductEditDto> Info(long id)
        {
            var ret = _productService.Info(id);
            return ApiResponse<ProductEditDto>.Succeeds(ret);
        }


        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("product/delete")]
        public ApiResponse Delete(long id)
        {
            _productService.Delete(id);
            return ApiResponse.Succeeds();
        }
    }
}